package com.thinkingcoder.tccache.core.command.common;

import static com.thinkingcoder.tccache.constant.CommandConstants.CommonCmd.PING;
import static com.thinkingcoder.tccache.constant.EncodeConstants.PONG;

import com.thinkingcoder.tccache.core.command.Command;
import com.thinkingcoder.tccache.core.model.Reply;
import com.thinkingcoder.tccache.core.TcCache;

/**
 * PING command.
 */
public class PingCmd implements Command {
    @Override
    public String name() {
        return PING;
    }

    @Override
    public Reply<?> exec(TcCache cache, String[] args) {
        String ret = PONG;
        if (args.length >= 5) {
            ret = "";
            for (int i = 4; i < args.length; i++) {
                if (i % 2 == 0) {
                    ret += args[i] + " ";
                }
            }

        }
        return Reply.string(ret);
    }
}
